Serve Stale
(MI.StaleContentCachePolicy)
Overview
TTL (time-to-live) specifies the amount of time a content item in the CDN cache is considered valid. When the TTL expires, an object is considered stale. Stale content is typically fetched from the origin. However you may decide that under certain conditions, it would be beneficial to serve stale content instead.
The Serve Stale rule can be used to instruct the CDN to serve stale objects (objects with expired TTL) under these conditions:
-
When the origin server is temporarily unable to serve the content, as indicated by specifying any of the following origin errors: 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout.
-
During the revalidation of content against the origin.
The decision to serve stale content should be considered carefully, and with regards to the nature of the content.
You can define this rule at the site level, and override it at the host or path level to specify exceptions.
Example
In this example, stale content will be served when the origin server returns a 500 or 502 code, and during revalidation of content against the origin.
{
"generic-metadata-type": "MI.StaleContentCachePolicy",
"generic-metadata-value": {
"stale-if-error": [
"500",
"502"
],
"stale-while-revalidating": true
}
}
Supported Properties
Field | Valid Values |
---|---|
stale-if-error | 500, 502, 503, 504 |
stale-while-revalidating | true, false |